<%@page contentType="text/html;charset=utf-8" pageEncoding="UTF-8"%>
<%@taglib prefix="t" tagdir="/WEB-INF/tags"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<t:template>
	<jsp:attribute name="include">
		<script type="text/javascript">
			function reloadTable() {
				var table = $('#merchTable').dataTable();
				table.fnReloadAjax();
			}

			var serverDatas = [ "categoryId", "name", "priceFrom", "priceTo" ];

			function pageInit() {
				createDataTable("merchTable", '<c:url value="/shop/sales/getSales"/>', [
						linkFormattedColDef(0, '<c:url value="/profile"/>', "username"), {
							"sName" : "name",
							"aTargets" : [ 1 ],
							"bSortable" : true,
							"mData" : function(data, type, full) {
								return '<a href="<c:url value="/shop/sales"/>/' + data.id + '">' + data.name + '</a>';
							}
						}, colDefNotSortable(2, "category.label"), colDef(3, "price"), dateColDef(4, "lastchange") ], false);
			}
		</script>
	</jsp:attribute>

	<jsp:attribute name="pagetitle">
		Hirdetések kezelése
    </jsp:attribute>
	<jsp:body>
		<div>
			<form class="form-horizontal" onsubmit="return false;">
				<div class="control-group">
					<label class="control-label" for="name">Megnevezés:</label>
					<div class="controls">
						<input type="text" id="name" name="name" placeholder="Megnevezés"
							autocomplete="off" onkeyup="reloadTable()">
					</div>
				</div>
				<div class="control-group">
					<label class="control-label" for="categoryId">Kategória:</label>
					<div class="controls">
						<select id="categoryId" name="categoryId" data-size="7"
							onchange="reloadTable()">
							<option value="0">Mind</option>
							${categoryOptions }
						</select>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label" for="priceFrom">Ár:</label>
					<div class="controls">
						<div class="input-append">
							<input type="number" id="priceFrom" name="priceFrom"
								onkeyup="reloadTable()" maxlength="7" /><span class="add-on">-tól</span>
						</div>
						<div class="input-append">
							<input type="number" id="priceTo" name="priceTo"
								onkeyup="reloadTable()" maxlength="7" /><span class="add-on">-ig</span>
						</div>
					</div>
				</div>
			</form>
		</div>
    	<table id="merchTable">
		    <thead>
				<tr>
					<th>Felhasználó</th>
					<th>Megnevezés</th>
					<th>Kategória</th>
					<th>Ár (Ft)</th>
					<th>Utolsó módosítás</th>
				</tr>
			</thead>
			<tbody>
				<tr>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
				</tr>
			</tbody>
			<tfoot>
				<tr>
					<th>Felhasználó</th>
					<th>Megnevezés</th>
					<th>Kategória</th>
					<th>Ár (Ft)</th>
					<th>Utolsó módosítás</th>
				</tr>
			</tfoot>
    	</table>
    </jsp:body>
</t:template>